package com.kunbo.cn.controller.core.approval;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kunbo.cn.entity.core.approval.TareExceptionApproval;
import com.kunbo.cn.entity.core.card.ICCard;
import com.kunbo.cn.service.core.approval.TareExceptionApprovalService;
import com.kunbo.cn.service.core.card.ICCardService;
import com.kunbo.cn.util.date.SDate;
import com.kunbo.cn.util.retu.BuildBean1;
import com.kunbo.cn.util.retu.CommonResult;
import com.kunbo.cn.util.retu.Pages;
import com.kunbo.cn.util.retu.ResultBean1;

/**
 *
 * @author bjl  
 * @date 2019年3月21日 
 */

@RestController
@RequestMapping("/TareExceptionApproval")
public class TareExceptionApprovalController {
	@Autowired
	private JdbcTemplate jdbc;
	@Autowired
	private TareExceptionApprovalService service;
	
	@PostMapping("/add")
	public CommonResult add(TareExceptionApproval tareApproval) {
		service.save(tareApproval);
		return new CommonResult(true,"操作成功",null);
	}
	@GetMapping("/createCode")
	public String createCode(){
		 String prex = "IC";
		 String bill_code= prex+SDate.getSystemDateYMDHMSToString();
		 return bill_code;
	}
	@GetMapping("/cardSerial")
	public String getCardSerial(){
		 String prex = "CY";
		 String card_serial= prex+SDate.getSystemDateYMDHMSToString();
		 return card_serial;
	}
		/**
		 * 
		 * 修改
		 *//*
		@PutMapping("/update")
		public CommonResult update(TareExceptionApproval tareApproval) {
			service.update(tareApproval);
			return new CommonResult(true,"操作成功",null);
		}
		*/
		@DeleteMapping("/delete")
		public CommonResult delete(String id) {
			service.delete(id);
			return new CommonResult(true,"操作成功",null);
		}
		/**
		 * 详情
		 * 
		 */
		@GetMapping("/findById")
		public TareExceptionApproval findById(String id) {
			TareExceptionApproval tare = service.findById(id);
			return tare;
		}
		
		@GetMapping("/list")
		public ResultBean1<Pages> exelist(
				@RequestParam String startTime,
				@RequestParam String endTime,
				@RequestParam String car_number,
				@RequestParam String material,
				@RequestParam String  state,
				@RequestParam Integer page,
				@RequestParam Integer pageSize
				){
			ResultBean1<Pages> result  = new ResultBean1<Pages>();
			return BuildBean1.buildResulttoPages(result, "success", "error", service.exelist(startTime,endTime,car_number,material,state,page,pageSize));
		}
		
		
		/**
		 * 
		 * 修改状态
		 */
		@GetMapping("/updateState")
		public CommonResult updateState(String id ,String state,String note,String auditor ) {
			service.updateState(id,state,note,auditor);
			return new CommonResult(true,"操作成功",null);
		}
}
